package com.huishen.edrivenew.widget;


import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.huishen.edrivenew.R;
import com.huishen.edrivenew.util.StringUtils;

/**
 * 自定义消息弹出框
 */
public class MessageDialogNew extends Dialog implements View.OnClickListener {

    private MassageListener msgListener;
    private boolean hideCancel = false;
    
    private String subj_name, coach_name, time, money, outline;
    private TextView subj_nameTv, coach_nameTv, timeTv, moneyTv, outlineTv, outline1Tv;
    private Button commit, cancel;

    public MessageDialogNew(Context context, String subj_name, String coach_name,
                            String time, String money, String outline, 
            MassageListener msgListener) {
        super(context, R.style.dataselectstyle);
        this.subj_name = subj_name;
        this.coach_name = coach_name;
        this.time = time;
        this.money = money;
        this.outline = outline;
        this.msgListener = msgListener;
    }

    public MessageDialogNew(Context context, int theme) {
        super(context, R.style.dataselectstyle);
    }

    public MessageDialogNew(Context context, boolean cancelable, OnCancelListener cancelListener) {
        super(context, R.style.dataselectstyle);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.setContentView(R.layout.dialog_message_new);
        registView();
        init();
    }

    private void registView() {
        subj_nameTv = (TextView) findViewById(R.id.subj_name);
        coach_nameTv = (TextView) findViewById(R.id.coach_name);
        timeTv = (TextView) findViewById(R.id.time);
        moneyTv = (TextView) findViewById(R.id.money);
        outlineTv = (TextView) findViewById(R.id.outline);
        outline1Tv = (TextView) findViewById(R.id.outline1);

        commit = (Button) findViewById(R.id.dialog_msg_commit);
        cancel = (Button) findViewById(R.id.dialog_msg_cancel);
    }

    /**
     * 隐藏取消按钮
     */
    public void setCancelHide() {
        hideCancel = true;
    }

    private void init() {
        subj_nameTv.setText(subj_name);
        coach_nameTv.setText(coach_name);
        timeTv.setText(time);
        moneyTv.setText(money);
        outlineTv.setText(outline);
        
        if(StringUtils.isEmpty(outline)) {
            outline1Tv.setVisibility(View.GONE);
        } else {
            outline1Tv.setVisibility(View.VISIBLE);
        }
        
        
        if (msgListener != null) {
            commit.setOnClickListener(this);
            cancel.setOnClickListener(this);
        }
        if (hideCancel) {
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(cancel.getLayoutParams());
            lp.setMargins(0, 0, 0, 0);
            cancel.setLayoutParams(lp);
            cancel.setVisibility(View.GONE);
        }
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.dialog_msg_commit:
                msgListener.setCommitClick();
                dismiss();
                break;
            case R.id.dialog_msg_cancel:
                msgListener.setCancelClick();
                dismiss();
                break;
        }
    }

}
